/**
 * 
 */
package tk.sunlatus.project.usermanage.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Arrays;
import java.util.Collection;

import org.apache.log4j.Logger;

import tk.sunlatus.project.common.domain.ProcessResult;
import tk.sunlatus.project.dbmanage.MyDataSource;
import tk.sunlatus.project.usermanage.domain.User;

/**
 * 用户管理持久化层，jdbc实现方式
 * 
 * @author sunlotus
 * @deprecated
 */
public class UserDaoJDBCImpl
// implements UserDao
{

    private static final Logger LOGGER = Logger.getLogger(UserDaoJDBCImpl.class);

    private MyDataSource dataSource = null;

    public User queryByID(String userID) {
        String sql = "select * from user where id = ?";
        User user = new User();
        user.setUserID("null");
        Connection conn = null;
        PreparedStatement stmt = null;
        ResultSet rs = null;
        try {
            conn = dataSource.getConnection();
            stmt = conn.prepareStatement(sql);
            stmt.setString(1, userID);
            rs = stmt.executeQuery();
            while (rs.next()) {
                user.setUserID(rs.getString("name"));
                LOGGER.debug("user.name=" + rs.getString("name"));
            }

        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            closeConnection(conn, stmt, rs);
        }
        return user;
    }

    public void setDataSource(MyDataSource dataSource) {
        this.dataSource = dataSource;
    }

    public MyDataSource getDataSource() {
        return dataSource;
    }

    public void closeConnection(Connection conn, Statement stmt, ResultSet rs) {
        if (rs != null) {
            try {
                rs.close();
                rs = null;
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

        if (stmt != null) {
            try {
                stmt.close();
                stmt = null;
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

        if (conn != null) {
            try {
                conn.close();
                conn = null;
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

    public boolean saveUser(User user) {
        // TODO 添加用户
        return false;
    }

    public boolean removeByID(String userID) {
        // TODO 删除用户
        return false;
    }

    public ProcessResult batchSaveUser(User[] users) {
        return batchSaveUser(Arrays.asList(users));
    }

    public ProcessResult batchSaveUser(Collection<User> users) {
        // TODO 批量导入用户
        return null;
    }

    public ProcessResult batchRemoveUsers(String[] userIDs) {
        return batchRemoveUsers(Arrays.asList(userIDs));
    }

    public ProcessResult batchRemoveUsers(Collection<String> userIDs) {
        // TODO Auto-generated method stub
        return null;
    }

    public boolean deregistration(String userID) {
        // TODO Auto-generated method stub
        return false;
    }

    public ProcessResult deregistrationUsers(String[] userIDs) {
        // TODO Auto-generated method stub
        return null;
    }

    public ProcessResult deregistrationUsers(Collection<String> userIDs) {
        // TODO Auto-generated method stub
        return null;
    }
}
